package app.demo.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springleaf.core.mvc.service.impl.SimpleBaseServiceImpl;

import app.demo.model.Customer;
import app.demo.service.CustomerService;

@SuppressWarnings("rawtypes")
@Service("customerService")
public class CustomerServiceImpl extends SimpleBaseServiceImpl<Customer> implements CustomerService {
	
	/**
	 * 登录
	 */
	public Customer login(Customer user) {
		String hql = "select obj from User obj where obj.username = ? and obj.password = ?";
		List list = getBaseDao().query(hql, new String[]{user.getUsername(),user.getPassword()});
		if(list.size() == 1){
			return (Customer) list.get(0);
		}
		return null;
	}

	@Override
	public Customer getUserByUsername(String username) {
		String hql = "select obj from User obj where obj.username = ?";
		List list = getBaseDao().query(hql, new String[]{ username });
		if(list.size() == 1){
			return (Customer) list.get(0);
		}
		return null;
	}

}
